using System;
using System.Collections.Generic;

namespace PingPong.GameEngine.Components
{

	public class PlayerAffinity
	{
		#region Members

		/// <summary>
		/// The first player.
		/// </summary>
		private Lazy<Player> firstPlayer;

		/// <summary>
		/// The second player.
		/// </summary>
		private Lazy<Player> secondPlayer;/// 

		#endregion

		#region Properties

		/// <summary>
		/// Gets the first player.
		/// </summary>
		/// <value>The first player.</value>
		public Player FirstPlayer
		{
			get
			{
				return this.firstPlayer.Value;
			}
		}

		/// <summary>
		/// Gets the second player.
		/// </summary>
		/// <value>The second player.</value>
		public Player SecondPlayer
		{
			get
			{
				return this.secondPlayer.Value;
			}
		}

		/// <summary>
		/// Gets the players.
		/// </summary>
		/// <value>The players.</value>
		public IEnumerable<Player> Players
		{
			get
			{
				yield return FirstPlayer;
				yield return SecondPlayer;
			}
		}

		#endregion

		#region Constructors

		/// <summary>
		/// Initializes a new instance of the <see cref="PingPong.GameEngine.Components.PlayerAffinity"/> class.
		/// </summary>
		public PlayerAffinity()
		{
			this.firstPlayer = new Lazy<Player>(() => new Player());
			this.secondPlayer = new Lazy<Player>(() => new Player());
		}

		#endregion

		#region Methods

		/// <summary>
		/// Sets the first player.
		/// </summary>
		/// <returns>The first player.</returns>
		/// <param name="player">Player.</param>
		public PlayerAffinity SetFirstPlayer(Player player)
		{
			this.firstPlayer = new Lazy<Player>(() => player);
			return this;
		}

		/// <summary>
		/// Sets the second player.
		/// </summary>
		/// <returns>The second player.</returns>
		/// <param name="player">Player.</param>
		public PlayerAffinity SetSecondPlayer(Player player)
		{
			this.secondPlayer = new Lazy<Player>(() => player);
			return this;
		}

		#endregion
	}
}

